package com.xinshujia.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinshujia.entity.AccelerationStatisticsEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-12 11:02       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 * 设备振动数据持久化
 */
@Mapper
public interface AccelerationStatisticsDao extends BaseMapper<AccelerationStatisticsEntity> {
    /**
     * 根据设备GUID获取设备振动数据
     *
     * @param deviceGuid 设备GUID
     * @param count      获取数据条数
     * @return 设备振动数据
     */
    @Select("SELECT * FROM AccelerationStatistics WHERE Channel = 0 AND DeviceGUID = #{deviceGuid} ORDER BY Time DESC LIMIT 0,#{count};")
    List<AccelerationStatisticsEntity> getAsByDeviceGuid(@Param("deviceGuid") String deviceGuid, @Param("count") int count);

    /**
     * 查询在线设备GUID （当前时间前10秒）
     */
    @Select("SELECT DISTINCT DeviceGUID FROM AccelerationStatistics WHERE Time >= NOW() - INTERVAL 10 SECOND;")
    List<String> selectOnlineDeviceGuids();
}